package com.bajiao.app.controller.product;

import com.bajiao.app.base.AppBaseController;
import com.bajiao.common.api.vo.RestResult;
import com.bajiao.common.web.entity.TableDataInfo;
import com.bajiao.service.product.ProductService;
import com.bajiao.vo.product.ProductDetailsResponse;
import com.bajiao.vo.product.ProductResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Api(tags = "商品接口")
@RestController
@RequestMapping("/api/v1/product")
public class RestProductController extends AppBaseController {

    @Resource
    private ProductService productService;

    @GetMapping(value = "/page")
    @ApiOperation(value = "商品分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", defaultValue = "10", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "storeId", value = "商家id", dataType = "String", required = true),
            @ApiImplicitParam(name = "classifyId", value = "分类id", dataType = "String", required = true),
    })
    public RestResult<TableDataInfo<ProductResponse>> getProductPage(@ModelAttribute("userId") String userId,
                                                                     @RequestParam("storeId") String storeId,
                                                                     @RequestParam("classifyId") String classifyId) {
        startPage();
        List<ProductResponse> productList = productService.getProductList(userId, storeId, classifyId);
        return success(getDataTable(productList));
    }

    @GetMapping(value = "/details")
    @ApiOperation(value = "商品详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId", value = "商家id", dataType = "String", required = true),
            @ApiImplicitParam(name = "productId", value = "产品id", dataType = "String", required = true),
    })
    public RestResult<ProductDetailsResponse> getProductDetails(@ModelAttribute("userId") String userId,
                                                                @RequestParam("storeId") String storeId,
                                                                @RequestParam("productId") String productId) {
        ProductDetailsResponse responses = productService.getProductDetails(userId, storeId, productId);
        return success(responses);
    }

    @GetMapping(value = "/recommend")
    @ApiOperation(value = "获取推荐商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", defaultValue = "10", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "storeId", value = "店铺id", dataType = "String", required = true),
            @ApiImplicitParam(name = "productIds", value = "当前商品id 多个,分割", dataType = "String", required = false)
    })
    public RestResult<TableDataInfo<ProductResponse>> getProductRecommend(@ModelAttribute("userId") String userId,
                                                                          @RequestParam("storeId") String storeId,
                                                                          @RequestParam(value = "productIds", required = false) String productIds) {
        startPage();
        List<ProductResponse> responseList = productService.getProductRecommend(userId, storeId, productIds);
        return success(getDataTable(responseList));
    }
}
